package com.rimi.service.impl;

import com.rimi.bean.Appointment;
import com.rimi.bean.Doctor;
import com.rimi.bean.Pets;
import com.rimi.commons.CommonResult;
import com.rimi.commons.ResultStatus;
import com.rimi.mapper.AppointmentMapper;
import com.rimi.service.AppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AppointmentServiceImpl implements AppointmentService {

    @Autowired
    AppointmentMapper appointmentMapper;

    /**
     * 根据用户Id查找宠物信息
     * @param userId
     * @return
     */
    @Override
    public List<Pets> findPetByUserId(Integer userId) {
        return appointmentMapper.findPetByUserId(userId);
    }

    /**
     * 根据日期查找医生信息
     * @param beginDate, endDate
     * @return
     */
    @Override
    public List<Doctor> findDoctorByDate(String beginDate, String endDate) {
        return appointmentMapper.findDoctorByDate(beginDate, endDate);
    }

    @Override
    public List<Doctor> findDoctorByWeek(String week) {
        return appointmentMapper.findDoctorByWeek(week);
    }

    /**
     * 添加挂号订单
     * @param appointment
     * @return
     */
    @Override
    public CommonResult addAppointment(Appointment appointment) {
        int res = appointmentMapper.addAppointment(appointment);
        return res == 1 ? CommonResult.onSuccess(null) : CommonResult.onFailed(ResultStatus.ADD_FAILED);
    }

    @Override
    public CommonResult deleteAppointmentByUser(String appointmentId) {
        int res = appointmentMapper.deleteAppointmentByUser(appointmentId);
        return res == 1 ? CommonResult.onSuccess(null) : CommonResult.onFailed(ResultStatus.DELETE_FAILED);
    }

    @Override
    public CommonResult deleteAppointmentByAdministrator(String appointmentId) {
        int res = appointmentMapper.deleteAppointmentByAdministrator(appointmentId);
        return res == 1 ? CommonResult.onSuccess(null) : CommonResult.onFailed(ResultStatus.DELETE_FAILED);
    }

    /**
     * 根据用户查询订单
     * @param userId
     * @return
     */
    @Override
    public List<Appointment> findAppointmentByUserId(Integer userId) {
        return appointmentMapper.findAppointmentByUserId(userId);
    }

    @Override
    public List<Appointment> findMedicalrecordsByUserId(Integer userId) {
        return appointmentMapper.findMedicalrecordsByUserId(userId);
    }
}
